package com.hexinfo.dmpro.component.data.transfer.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;


public class StreamGobbler extends Thread {
    InputStream in;
    String charset;
    StringBuffer sb = new StringBuffer();

    public StreamGobbler(InputStream in, String charset) {
        this.in = in;
        this.charset = charset;
    }

    public String getContent() {
        return sb.toString();
    }

    public void run() {
        try {
            InputStreamReader read = new InputStreamReader(in, charset);
            BufferedReader bufferedReader = new BufferedReader(read);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line).append(System.getProperty("line.separator"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
